<?php

namespace Modules\Admin\Http\Controllers;

use Illuminate\Support\Facades\Request;
use Modules\Admin\Service\CheckpointMakeDateService;
use Modules\Admin\Service\CheckpointService;
use Modules\Admin\Service\OrderCheckpointService;
use Modules\Admin\Service\ShopCheckpointServiceProductService;
use Modules\Admin\Service\ShopCheckpointServiceSpecsService;
use Modules\Admin\Service\ShopService;


class ShopController extends BaseController
{
    /**
     * 门店列表
     */
    public function index()
    {
        $data = Request::input();
        $list = ShopService::get_list($data);

        echo_error($list);
        return view('admin::shop.index', ['list' => $list, 'data' => $data]);
    }

    /**
     * 维修店详情
     */
    public function shop_detail()
    {
        $n_shop_id = intval(Request::input('id', 0));

        $detail = ShopService::get_shop_detail($n_shop_id);

        return view('admin::shop.shop_detail', $detail);
    }

    /**
     * 检测站开放日期
     */
    public function checkpoint_appointment_date()
    {
        try {
            $n_shop_id = intval(Request::input('id', 0));
            $arr_where = ['checkpoint_id' => $n_shop_id];
            $res = CheckpointMakeDateService::get_list_by_shopid($arr_where);
            echo_error($res);
            return view('admin::shop.checkpoint_appointment_date', $res['data']);

        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }

    /**
     * 检测站规格
     */
    public function checkpoint_service_specs()
    {
        try {
            $n_shop_id = intval(Request::input('id', 0));
            $arr_where = ['shop_id' => $n_shop_id];
            $res = ShopCheckpointServiceSpecsService::get_list_by_shopid($arr_where);
            echo_error($res);
            return view('admin::shop.checkpoint_service_specs', ['arr_data' => $res['data']]);
        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }

    /**
     * 检测站价目表
     */
    public function checkpoint_service_product()
    {
        try {
            $n_shop_id = intval(Request::input('id', 0));
            $arr_where = ['shop_id' => $n_shop_id];
            $res = ShopCheckpointServiceProductService::get_list_by_shopid($arr_where);
            echo_error($res);
            return view('admin::shop.checkpoint_service_product', $res['data']);

        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }

    /**
     * 检测站年检预约订单
     */
    public function checkpoint_appointment_order()
    {
        try {
            $arr_input = Request::input();
            $n_shop_id = intval($arr_input['id']);
            $res = OrderCheckpointService::all_order_list_by_shopid($n_shop_id, $arr_input);
            echo_error($res);
            return view('admin::shop.checkpoint_appointment_order', $res['data']);
        } catch (\Exception $exception) {
            return ['state' => 1, 'msg' => '失败', 'data' => [], 'error' => $exception->getMessage()];
        }
    }

    /**
     * 维修店商品列表
     */
    public function admin_shop_goods_list()
    {
        try {
            $n_shop_id = intval(Request::input('id', 0));
            $arr_where = ['shop' => $n_shop_id];
            $res = ShopService::admin_shop_goods_list($arr_where);

            echo_error($res);
            return view('admin::shop.shop_goods_list', ['arr_data' => $res['data']]);

        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }

    /**
     * 维修店服务商品列表
     */
    public function admin_shop_repair_list()
    {
        try {
            $n_shop_id = intval(Request::input('id', 0));
            $arr_where = ['repairstore_id' => $n_shop_id];
            $list = ShopService::admin_shop_repair_list($arr_where);

            echo_error($list);
            return view('admin::shop.shop_repair_list', ['list' => $list]);

        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }

    /**
     * 添加道路救援商铺-页面
     */
    public function road_help_add_page()
    {
        try {
            return view('admin::shop.road_help_add_page');

        } catch (\Exception $exception) {
            return hello_error('失败', [], $exception->getMessage());
        }
    }

    /**
     * 添加道路救援商铺-操作
     */
    public function road_help_add()
    {
        try {
            $arr_input = Request::input();
            filter_input_data($arr_input);

            $arr_input['cate'] = 3;

            shiwu_start();
            $result = ShopService::add_road_help_shop($arr_input);
            shiwu_end($result);

            return $result;
        } catch (\Exception $exception) {
            return hello_error('失败-' . $exception->getMessage(), [], $exception->getMessage());
        }
    }


    /**
     * 商户审核列表
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function verify_list()
    {
        $data = Request::input();
        $list = ShopService::verify_list($data);

        echo_error($list);
        return view('admin::shop.verify_list', $list);
    }

    /**
     * 商户审核详情
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function shop_info()
    {
        $n_shop_id = intval(Request::input('id', 0));

        $detail = ShopService::get_shop_info($n_shop_id);

        return view('admin::shop.shop_info', $detail);
    }

    /**
     * 商户审核
     * @return array
     * @throws \Exception
     */
    public function examine()
    {
        $data = Request::all();

        shiwu_start();
        $res = ShopService::examine($data);
        shiwu_end($res);

        return $res;
    }

    /**
     * 是否直营店
     */
    public function change_type()
    {
        $arr_input = Request::input();

        return ShopService::change_type($arr_input);
    }
}
